package com.wisdytech.ccdserver.common;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.util.Collection;

/**
 * 分表
 *
 * @author Hehaifeng
 * @date 2021/10/12 11:47
 */

public class PreciseModuloShardingTableAlgorithm implements PreciseShardingAlgorithm<String> {

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {

        String tableNameStr = "";

        for (String tableName : collection) {
            tableNameStr = tableName;
            //根据获取到的工序code拼接
            return "`"+tableName + "_" + preciseShardingValue.getValue().toUpperCase()+"`";
        }
        return "`" + tableNameStr + "`";
    }

}
